// const host = 'http://h5dfcshop.dfcshop.com/apis/dfcapi/api/2.0/'
//const host = 'http://testh5dfcshop.dfcshop.com/apis/dfcapi/api/2.0/'
 
// const host = 'https://testapi.dfcshop.com/dfcapi/api/2.0/'
const host = 'https://api.dfcshop.com:8117/dfcapi/api/2.0/'  /// 正式

function request (url, method, data, header = {}) {
  // wx.showLoading({
  //   title: '加载中' // 数据请求前loading
  // })
 
  return new Promise((resolve, reject) => {
 
    wx.request({
      url: host + url, // 仅为示例，并非真实的接口地址
      method: method,
      data: data,
      headers: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        wx.hideLoading()
        resolve(res.data)
      },
      fail: function (res) {
        wx.hideLoading() //结束加载
        // reject(false)
      },
      complete: function () {
        wx.hideLoading()
      } 
    })
  })
}
 
const req = {
  data: '',
  apikey: '03892de79f9611e8b36c00163e0e500c',
  token:wx.getStorageSync('token')
  // token: 'AGFQYVM1U2cAMQ9sXTEOPQ5oVjcBfAA/AzUCMlppUT9QLFBlBGdXZgY2CGUNfQgzBGYDYVE1BTsFLgA2V3hXOgB8UGVTMlNgACoPf10rDi4Oa1YxAWEAPg==',
};
function get (obj) {
  req.data= obj.data
  return request(obj.url, 'GET', req)
}
 
function post (obj) {
  req.data= obj.data
  return request(obj.url, 'POST', req)
}
 
export default {
  request,
  get,
  post,
  host
}